<?php
/**
 * 阿里云OSS
 * User: linyi(linyi05@baidu.com)
 * Date: 2017/9/7
 * Time: 8:21
 */

namespace App\Models;

use OSS\OssClient;
use OSS\Core\OssException;

class OssUtil
{
    const OSS_PHOTO_BUCKET = 'meizucampus-photo';
    const OSS_FILES_BUCKET = 'meizucampus-files';
    const OSS_PHOTO_URL = 'http://photo.m-union.net.cn/';
    const OSS_FILES_URL = 'http://files.m-union.net.cn/';
    const OSS_ASSETS_URL = 'http://assets.m-union.net.cn/';

    private static $instance;

    private function __construct()
    {
    }

    private function __clone()
    {
    }

    public static function getInstance()
    {
        if (self::$instance == null) {
            try {
                self::$instance = new OssClient(env('OSS_ACCESS_ID'), env('OSS_ACCESS_KEY'), env('OSS_ENDPOINT'));
            } catch (OssException $e) {
                \Log::warning('实例化OSS出错：' . $e->getMessage());
                return null;
            }
        }
        return self::$instance;
    }
}